<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>


<div class="header-bottom">
	<div class="container">
		<div class="logo">
			<a href="index.html"><h1>
					Gat<span>o</span>
				</h1></a>
		</div>
		<span class="menu"></span>
		<div class="top-menu">
			<ul>
				<nav>

					<li><a class="active"
						href="${pageContext.request.contextPath}/frontdevel/index.jsp">Home</a></li>
					<li><a
						href="${pageContext.request.contextPath}/frontdevel/fosterFamily.jsp">FosterMall</a></li>
					<li id="usercenter"><a>UserCenter</a></li>
					<li><a
						href="${pageContext.request.contextPath}/frontdevel/abouts.jsp">AboutUs</a></li>
					<li id='loginlable'><a href='#' id='tologinform'>Login</a></li>
					<li id='registerlable'><a href="#" id='toregisterform'>Register</a></li>
					<li><a id='userlable'>${user.uname}</a>
						<dl>
							<dd id="myupdate">
								<a href="#" id="touseredit">修改信息</a>
							</dd>
							<dd id="myquit">
								<a href="#">退了</a>
							</dd>
						</dl></li>
				</nav>
			</ul>
		</div>
		<!-- script for menu -->
		<script>
			$("span.menu").click(function() {
				$(".top-menu").slideToggle("slow", function() {
					// Animation complete.
				});
			});
			$(document).ready(function(){
				$(".top-menu a").removeClass("active");
				var url = location.href;
				$(".top-menu a").each(function(){		
					if(url.indexOf($(this).prop("href"))>=0){
						$(this).addClass("active");
					}
				})
			});
		</script>
		<!-- script for menu -->
		<div class="clearfix"></div>
	</div>
</div>

<!-- 登入按钮弹出层 -->
<div class="layui-row" id="loginform" style="display: none;">
	<form class="form-horizontal">
		<span id="mycount-msg" class="error" style="margin-top: 5px;"></span>
		<div class="form-group">
			<input type="text" class="form-control" id="inputEmail3"
				placeholder="用户名"> <i class="fa fa-user"></i>
		</div>
		<span id="mypassword-msg" class="error" style="margin-top: 5px;"></span>
		<div class="form-group help">
			<input type="password" class="form-control" id="inputPassword3"
				placeholder="密　码"> <i class="fa fa-lock"></i>
		</div>
		<div class="form-group">
			<div class="main-checkbox">
				<input type="checkbox" value="None" id="checkbox1" name="check">
				<label for="checkbox1"></label>
			</div>
			<span class="text">记住密码</span>
			<button id="mylogin" class="btn btn-default">登录</button>
		</div>
	</form>
</div>
<!--登入按钮弹出层 -->

<!-- 注册按钮弹出层 -->
<div class="layui-row" id="registerform" style="display: none;">
	<div class="layui-col-md11">
		<form class="layui-form" action="" id='myregister'>
			<div class="layui-form-item">
				<label class="layui-form-label">昵称：</label>
				<div class="layui-input-block">
					<input type="text" name="uname" id="name" lay-verify="title"
						autocomplete="off" placeholder="请输入标题" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">密码：</label>
				<div class="layui-input-block">
					<input type="password" name="upwd" id="pwd" lay-verify="title"
						autocomplete="off" placeholder="请输入标题" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">性别：</label>
				<div class="layui-input-block">
					<input type="radio" name="usex" value="男" title="男" checked="">
					<input type="radio" name="usex" value="女" title="女">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">地址：</label>
				<div class="layui-input-block">
					<input type="text" name="uaddress" lay-verify="title"
						autocomplete="off" placeholder="请输入标题" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">电话：</label>
				<div class="layui-input-block">
					<input type="text" name="utel" lay-verify="title"
						autocomplete="off" placeholder="请输入标题" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button type="button" class="layui-btn layui-btn-normal"
						id="subbtn1" lay-submit="" lay-filter="tijiao1">注册</button>
				</div>
			</div>

		</form>
	</div>
</div>
<!-- 注册按钮弹出层 -->

<!-- 编辑按钮弹出层 -->
<div class="layui-row" id="useredit" style="display: none;">
	<div class="layui-col-md11">
		<form class="layui-form" action="" id='myform'>
			<div class="layui-form-item">
				<label class="layui-form-label">用户编号：</label>
				<div class="layui-input-inline">
					<input type="text" name="uid" class="layui-input" id="userId"
						value="" readonly>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">用户名：</label>
				<div class="layui-input-inline">
					<input type="text" name="uname" class="layui-input" id="userName"
						value="">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">密码：</label>
				<div class="layui-input-inline">
					<input type="text" name="upwd" class="layui-input" id="userPwd"
						value="">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">性别：</label>
				<div class="layui-input-block">
					<input type="radio" name="usex" value="男" title="男" checked=true
						id="userSexMan"> <input type="radio" name="usex" value="女"
						title="女" id="userSexWoman">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">手机号码：</label>
				<div class="layui-input-inline">
					<input type="tel" name="utel" lay-verify="required|phone"
						autocomplete="off" class="layui-input" id="userTel" value="">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">地址：</label>
				<div class="layui-input-inline">
					<input type="text" name="uaddress" class="layui-input"
						id="userAddress" value="">
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button type="button" class="layui-btn layui-btn-normal"
						id="subbtn" lay-submit="" lay-filter="tijiao">提交</button>
				</div>
			</div>
		</form>
	</div>
</div>
<!-- 编辑按钮弹出层结束 -->

<!--  -->
<script type="text/javascript">
if(${empty user}){
	$('#usercenter').hide();
}
console.log(${user.ulevel==1});
console.log(${user.ulevel==2});
/*如果是寄养家庭登录 就走queryOrderByname */
if(${user.ulevel==1}){
	$('#usercenter a').attr("href","${pageContext.request.contextPath}/orders/queryOrder?ouid=${user.uid}");
	$('#userlable').attr("href","${pageContext.request.contextPath}/orders/queryOrder?ouid=${user.uid}");
}else{
	$('#usercenter a').attr("href","${pageContext.request.contextPath}/orders/queryOrderByname?otuname=${user.uname}");
	$('#userlable').attr("href","${pageContext.request.contextPath}/orders/queryOrderByname?otuname=${user.uname}");
}

</script>

<script type="text/javascript">
$(document).ready(function(){ 
		var flag=${user!=null};
    if(flag){
		$('#loginlable').hide();
		$('#registerlable').hide();	
		$('#userlable').show();
	　　}else{
		$('#userlable').hide();
	　　}
	}); 
	

<!-- 4.28 wwb 登入按钮弹出层 -->
	layui.use('form', function() {
		var form = layui.form;
		$('#tologinform').on('click', function() {
			$('#inputEmail3').val("");
			$('#inputPassword3').val("");
			$('#mycount-msg').empty();
			$('#mypassword-msg').empty();
			layer.open({
				type : 1,
				title : "用户登入",
				//skin : 'layui-layer-rim', //加上边框
				area : [ '400px', '300px' ], //宽高
				content : $("#loginform"),
				shade : [ 0.8, '#393D49' ],
			});
		})

		$('#toregisterform').on('click', function() {
			layer.open({
				type : 1,
				title : "用户注册",
				skin : 'layui-layer-rim', //加上边框
				area : [ '550px', '400px' ], //宽高
				content : $("#registerform"),
			});
			form.render;
		})
		
		//注册按钮事件
layui.form.on('submit(tijiao1)', function(data) {
	var getuname=$('#name').val();
	var getupwd=$('#pwd').val();
	console.log(getuname+"-,-"+getupwd);
	if(getuname==null|| getuname==""){
		layer.msg("账户不能为空")
	

	}else if(getupwd==null|| getupwd==""){
		layer.msg("密码不能为空")
	}
	else{
		$.ajax({
			type : "post",
			url : "../insert",
			data : JSON.stringify(data.field),
			contentType:'application/json; charset=UTF-8',
			success : function(cm) {
				layer.msg(cm.msg, {
					time : 2000,
					icon : 1
				}, function() {
					if (cm.msg == "注册成功") {
						layer.closeAll();
					}
				})
			}
		})
	}

})
          //登录名字失焦事件
			$('#name').on('blur',function(){
			var name=$('#name').val();
			if(name==null || name==""){
				$('#name').attr("placeholder","用户名不能为空");
				$('#name').css("borderColor","red");
				return false;
			}else{
				$('#name').css("borderColor","Silver");
				$.ajax({
					'type' : 'get',
					'url' : '../nameCheck/' + name,
					'success' : function(data) {
						if (data==true){	
							$('#name').val("");
							$('#name').attr("placeholder","用户名已经存在");
							$('#name').css("borderColor","red");
						}else{
							$('#name').css("borderColor","Silver");
						}
					}
				});				
			}
			$('#name').empty();
			return true;
		})	
		$('#inputEmail3').on('blur',function(){
			var name=$('#inputEmail3').val();
			//console.log(name);
			if(name==null || name==""){
				$('#mycount-msg').html("<font color='red'>用户名不能为空</font>");
				return false;
			}else{
				$.ajax({
					'type' : 'get',
					'url' : '../nameCheck/' + name,
					'success' : function(data) {
						if (data != true) {
							$('#mycount-msg').html("<font color='red'>用户名不存在</font>");
							return false
						}
					}
				});				
			}
			$('#mycount-msg').empty();
			return true;
		})
				
		$('#inputPassword3').on('blur',function(){
			var password = $('#inputPassword3').val();
			if (password == null || password == "") {
				// 提示错误
				$('#mypassword-msg').html("<font color='red'>密码不能为空</font>");
				return false;
			}
			var reg = /^\w{3,10}$/;
			if (!reg.test(password)) {
				$('#mypassword-msg').html("<font color='red'>输入3-10个字母或数字或下划线</font>");
				return false;
			}
			$('#mypassword-msg').empty();
			return true;
		})
		
		$('#mylogin').on('click',function(){
			var name=$('#inputEmail3').val();
			var password = $('#inputPassword3').val();
			$.ajax({
				type : "post",
				url : "../doCheck",
				data : {
					'name' : name,
					'pwd' : password
				},
				success : function(Msg) {
					//console.log(Msg.msg)
					if (Msg.msg == "登录成功") {
						layer.closeAll();
						$('#loginlable').hide();
						$('#registerlable').hide();
						window.location.reload();
					} else if(Msg.msg == "账号被禁用"){
						$('#mycount-msg').html(Msg.msg);
					}else
					{
						$('#mypassword-msg').html(Msg.msg);
					}
				}
			})
		})
		
		$('#myquit').on('click',function(){
			//console.log('tuichu');
			$.ajax({
				type : "post",
				url : "../invalidate",
				data : {
					'sign':'front'
				},
				complete:function(XMLHttpRequest, textStatus){
					console.log("执行了吗");
					window.location.href="${pageContext.request.contextPath}/frontdevel/index.jsp";
					//window.location.reload();
				}
			})
		})
		
		$('#touseredit').on('click', function() {
			$('#userId').val("${user.uid}");
			$('#userName').val("${user.uname}");
			$('#userPwd').val("${user.upwd}");
			
			$("#userTel").val("${user.utel}");
			$("#userAddress").val("${user.uaddress}");
			layer.open({
				type : 1,
				title : "修改资料",
				//skin : 'layui-layer-rim', //加上边框
				area : [ '400px', '500px' ], //宽高
				content : $("#useredit"),
				/* shade : [ 0.8, '#393D49' ], */
			});
			
			

			//编辑--监听提交
			layui.form.on('submit(tijiao)', function(data) {
				
				$.ajax({
					'type' : 'put',
					'url' : '../update',
					'data' : JSON.stringify(data.field),
					'contentType' : 'application/json',
					'success' : function(data) {
						if (data == true) {
							layer.closeAll();
							layer.open({
								type : 1,
								title : "用户登入",
								//skin : 'layui-layer-rim', //加上边框
								area : [ '400px', '300px' ], //宽高
								content : $("#loginform"),
								shade : [ 0.8, '#393D49' ],
							});
						}
					}
				});
			});

		})
	})
	
	
</script>
